<template>
  <div ref="mainCon" class="container">
    <topTitle
      v-if="!hiddleToolBar"
      :titleText="titleText"
      :titleExplain="titleExplain"
    ></topTitle>
    <div class="mainCon">
      <el-row class="toolbar searchInputWidth" style="padding-bottom: 0">
        <el-form :inline="true" :model="filterField" ref="searchConditions">
          <el-col :lg="8" :xl="6">
            <el-form-item label="用户类型" class="row-padding-bottom">
              <el-select
                v-model="filterField.userType"
                filterable
                placeholder="请选择"
                clearable
                :popper-append-to-body="false"
              >
                <el-option label="企业用户" value="COMPANY"></el-option>
                <el-option label="个人用户" value="PERSONAGE"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :lg="8" :xl="6">
            <el-form-item label="用户名称" class="row-padding-bottom">
              <el-input
                v-model="filterField.qaName"
                placeholder="请输入"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
          <template v-if="advanced">
            <el-col :lg="8" :xl="6">
              <el-form-item label="提问时间" class="row-padding-bottom">
                <timeSelection
                  @getStartTimeValue="getStartTimeValue"
                  @getEndTimeValue="getEndTimeValue"
                ></timeSelection>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="回复状态" class="row-padding-bottom">
                <el-select
                  v-model="filterField.status"
                  filterable
                  placeholder="请选择"
                  clearable
                  :popper-append-to-body="false"
                >
                  <el-option label="已回复" value="REPLYED"></el-option>
                  <el-option label="待回复" value="UNREPLY"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </template>
          <el-form-item>
            <a
              @click="toggleAdvanced"
              style="margin-left: 40px; color: #409eff; cursor: pointer"
              class="btnColor"
            >
              {{ advanced ? '收起' : '展开' }}
              <i
                :class="advanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
              ></i>
            </a>
            <el-button
              type="primary"
              icon="icon iconfont iconchazhao1"
              @click="searchList"
              class="searchBtn"
            >
              <span>搜索</span>
            </el-button>
          </el-form-item>
          <el-form-item>
            <exportBtn
              :dataLen="tableList.length"
              :filterField="filterField"
              responseType="get"
              api="api-a/question/questionExport"
            ></exportBtn>
          </el-form-item>
        </el-form>
      </el-row>
      <div class="spacing"></div>
      <div
        ref="tableBox"
        :class="hiddleToolBar ? 'tableBoxCur tableBox' : 'tableBoxCur'"
      >
        <el-table
          :data="tableList"
          ref="tableBox1"
          :max-height="tableHeight"
          v-loading="loading"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
          highlight-current-row
          stripe
          style="border: 1px solid #dfe6ec"
        >
          <el-table-column prop="userType" label="用户类型" min-width="100">
          </el-table-column>
          <el-table-column
            prop="qaName"
            label="用户名称"
            :formatter="formatTd"
            width="230"
          >
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.qaName"
                :columnName="'qaName'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            prop="description"
            label="问题描述"
            :formatter="formatTd"
            width="230"
          >
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.description"
                :columnName="'description'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            prop="createTime"
            label="时间"
            align="center"
            :formatter="formatTd"
            min-width="150"
          ></el-table-column>
          <el-table-column
            prop="status"
            label="状态"
            align="center"
            :formatter="formatTd"
            min-width="150"
          >
            <template slot-scope="scope">
              <span style="color: #ffc100" v-if="scope.row.status == 'UNREPLY'"
                >待回复</span
              >
              <span style="color: #5fab2b" v-if="scope.row.status == 'REPLYED'"
                >已回复</span
              >
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="left"
            :formatter="formatTd"
            fixed="right"
            min-width="110px"
          >
            <template slot-scope="scope">
              <el-link type="primary" @click="toDetail(scope.row)"
                >查看详情</el-link
              >
              <!-- v-hasBtn="['mProjectCompany:detail', 'projectList:detail']" -->
            </template>
          </el-table-column>
          <!-- 表格数据为空时，页面显示 -->
          <div slot="empty" v-show="isShow">
            <emptyTable emptyText="暂无相关信息"></emptyTable>
          </div>
        </el-table>
        <!-- filterField为搜索条件 -->
        <!-- getTableList为获取子组件的数据 -->
        <Pagination
          ref="pagination"
          @getList="getTableList"
          :filterField="filterField"
          :requestUrl="requestUrl"
        ></Pagination>
      </div>
    </div>
  </div>
</template>

<script>
import scrollTable from '@/mixin/scrollTable.js'

export default {
  name: 'answerQuestionList',
  mixins: [scrollTable],
  data() {
    return {
      titleText: '问题答疑',
      titleExplain: '个人/企业用户通过公众号提交的问题，可通过此功能查询及回复',
      //表格数据
      tableList: [],
      requestUrl: 'api-a/question/questionPageList',
      pageSize: 20,
      pageNo: 1,
      date: [],
      //搜索条件
      filterField: {
        userType: '', //用户类型
        qaName: '',
        startTime: '',
        endTime: '',
        status: '',
      },
      isShow: false, //列表加载
      loading: true,
      advanced: false,
    }
  },
  created() {
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData()
    })
  },
  activated() {
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData(this.pageNo, this.pageSize)
    })
  },
  methods: {
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    getTableList(data) {
      this.tableList = data
      this.loading = false
      if (this.tableList.length < 1) {
        this.isShow = true
      }
    },
    // 搜索
    searchList() {
      this.$refs.pagination.getTableListData()
    },
    //查看详情
    toDetail(row) {
      this.$router.push({
        path: '/home/answerQuestion/answerQuestionDetail',
        name: 'answerQuestionDetail',
        query: {
          id: row.id,
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/answerQuestion/answerQuestionList',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
    /**
     * @description: 获取开始日期
     * @param {*} urls
     * @param {*} datas
     */
    getStartTimeValue(val) {
      if (val) {
        this.filterField.startTime = val
      } else {
        this.filterField.startTime = ''
      }
    },
    /**
     * @description: 获取结束日期
     * @param {*} urls
     * @param {*} datas
     */
    getEndTimeValue(val) {
      if (val) {
        this.filterField.endTime = val
      } else {
        this.filterField.endTime = ''
      }
    },
  },
}
</script>

<style lang="less" scoped>
.mainCon {
  top: 210px;
  @media only screen and (max-width: 1366px) {
    /deep/.searchInputWidth .el-form--inline .el-form-item__label {
      width: 80px;
    }
  }
}
@import '../../../static/css/filterArea.less';
</style>
